#include "keybd.h"

#define PORT_KEYDAT 0x0060
#define PORT_KEYSTA  0x0064
#define PORT_KEYCMD 0x0064
#define KEYSTA_SEND_NOTREADY 0x02
#define KEYCMD_WRITE_MODE 0x60
#define KBC_MODE 0x47
#define KEYCMD_SENDTO_MOUSE 0xD4
#define MOUSECMD_ENABLE 0xF4

STATIC INLINE VOID WaitKeyboard(VOID){
    REG BYTE bState;
    do{
        __inbyte(PORT_KEYSTA, bState);
    }while(bState & KEYSTA_SEND_NOTREADY);
}

VOID InitKeyboard(VOID){
    WaitKeyboard();
    __outbyte(PORT_KEYCMD, KEYCMD_WRITE_MODE);
    WaitKeyboard();
    __outbyte(PORT_KEYDAT, KBC_MODE);
}

VOID InitMouse(VOID){
    WaitKeyboard();
    __outbyte(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);
    WaitKeyboard();
    __outbyte(PORT_KEYDAT, MOUSECMD_ENABLE);
}